import { SET_DICT, REMOVE_DICT, CLEAN_DICT } from "../constant";

const initialState = [];

const dictReducer = (state = initialState, action) => {
const { type, key, value } = action;
//console.log('dictReducer', state, action);
  switch (type) {
    case SET_DICT:
        //console.log('SET_DICT', key, value);
        const dicts = state.find((item) => item.key === key) ? state : [...state, { key, value }];
        return dicts;
    case REMOVE_DICT:
      return state.filter((item) => item.key !== key);
    case CLEAN_DICT:
      //console.log('CLEAN_DICT');
      return [];
    default:
      return state;
  }
}

export default dictReducer;